package com.licq.ldoc.parser.impl.annotation;

import java.lang.annotation.Annotation;

import net.sf.oval.constraint.Size;

import com.licq.ldoc.domain.AbstractNode;
import com.licq.ldoc.domain.Occurrencies;
import com.licq.ldoc.parser.AnnotationParsee;
import com.licq.ldoc.parser.impl.TargetIgnorableAnnotationParsee;

public class SizeAnnotationParsee extends TargetIgnorableAnnotationParsee {
	
	public SizeAnnotationParsee(AnnotationParsee successor) {
		super(successor);
	}

	@Override
	protected void doParseTo(AbstractNode node, Annotation annotation) {
		Size size = (Size) annotation;
		int minSizeValue = size.min();
		int maxSizeValue = size.max();
		Occurrencies occurrencies = node.getOccurrences();
		if (occurrencies.getLeast() < minSizeValue) {
			occurrencies = occurrencies.clone();
			occurrencies.setLeast(minSizeValue);
			node.setOccurrences(occurrencies);
		}
		if (maxSizeValue != Integer.MAX_VALUE && (occurrencies.getMost() == -1 
				|| occurrencies.getMost() > maxSizeValue)) {
			occurrencies = occurrencies.clone();
			occurrencies.setMost(maxSizeValue);
			node.setOccurrences(occurrencies);
		}
	}
	
}
